package com.itstherules.jmsunit.mock;

import static com.itstherules.jmsunit.JmsUnit.sender;
import static com.itstherules.jmsunit.JmsUnit.mock;
import static com.itstherules.jmsunit.expectation.Expectations.eq;
import static com.itstherules.jmsunit.expectation.Expectations.headers;

import org.junit.Test;

import com.itstherules.jmsunit.JmsInlineMock;
import com.itstherules.jmsunit.JmsSender;
import com.itstherules.jmsunit.managers.QueueManagersFactory.QueueManagerType;
import com.itstherules.jmsunit.mock.QueueRead;

public class AnywhereOnTheQueueTest {

	@Test
	public void canPullFromAnywhereOnTheQueue() throws Exception {
		JmsInlineMock unit = mock("vm://localhost:61616", QueueManagerType.ActiveMQ);
		JmsSender sender = sender("red", "vm://localhost:61616", QueueManagerType.ActiveMQ);

		unit.expects().through("red", QueueRead.ANYWHERE).with(eq("theThirdRedMessage"));
		unit.expects().through("red", QueueRead.ANYWHERE).with(eq("theFirstRedMessage"));
		unit.expects().through("red", QueueRead.ANYWHERE).with(eq("theSecondRedMessage"));
		unit.expects().queueIsEmpty("red");

		sender.send("theFirstRedMessage", headers("RedEndPoint"));
		sender.send("theSecondRedMessage", headers("RedEndPoint"));
		sender.send("theThirdRedMessage", headers("RedEndPoint"));
		
		unit.verifyAndClose();
	}
}